<template>
  <div>
    <div class="table-operator" v-if="stage !== '05010' && stage !== '05050'">
      <a-button :loading="genLoading" type="primary"
                style='background-color: #FFA500;border:0' icon="download" @click="handleGenerateReport">
        生成报告初稿
      </a-button>
<!--      <a-upload
        name="file"
        :showUploadList="false"
        :multiple="false"
        :data="queryParam"
        :headers="tokenHeader"
        :action="url.importExcelUrl"
        @change="handleImportExcel"
        accept=".docx, .doc, .xlsx, .xls, .pdf, .jpeg, .png"
      >
        <a-button type="primary" style="background-color: #1ea489; border: 0">导入 </a-button>
      </a-upload>-->
<!--      <a-button type="primary"
                style='background-color: #FFA500;border:0' @click="OnExportList">
        导出
      </a-button>-->
<!--      <a-button type="primary" style="background-color: #1a91b3; border: 0" @click="OnExportTemp"> 模板下载 </a-button>-->
      <!-- <a-button type="primary"
                @click="showConfirm">
        提交审核
      </a-button>
      <a-popconfirm title='确定生成吗?' @confirm="() => setApproveReason('1')">
        <a-button>
          同意
        </a-button>
      </a-popconfirm>
      <a-popconfirm title='确定生成吗?' @confirm="() => setApproveReason('2')">
        <a-button type="danger">
          拒绝
        </a-button>
      </a-popconfirm> -->
    </div>
<!--    <div v-if="stage !== '05010' && stage !== '05050'" class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
      <i class="anticon anticon-info-circle ant-alert-icon"></i>已选择&nbsp;<a style="font-weight: 600">{{
      selectedRowKeys.length }}</a>项&nbsp;&nbsp;
      <a style="margin-left: 24px" @click="onClearSelected">清空</a>
    </div>-->

<!--    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      @change="handleTableChange"
      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}">-->
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange">
      <span slot="proName" slot-scope="text">
         <j-ellipsis :value="text" :length="20" />
      </span>
<!--      <span slot="wtms" slot-scope="text">
         <j-ellipsis :value="text" :length="20" />
      </span>-->
<!--       <span slot="actionName">
         操作
      </span>-->
<!--      <span slot="action" slot-scope="text, record">
        <a v-if="stage !== '05010' && stage !== '05050'" @click="handleEdit(record,'取证')">取证</a>
        <a-button v-else type="link" @click="handleCheck(record,'查看')">查看</a-button>
      </span>-->
    </a-table>
    <CheckAndEditModel ref="modalForm" :id="id" :bsjdwName="bsjdwName" :bsjdw="bsjdw" :protype="protype" :type="type"
                       @ok="modalFormOk"></CheckAndEditModel>
    <SelectApprove ref='approver' :id='id' @submitData='handleSubmit'></SelectApprove>
    <SetReason ref='setReason' @approveReason='approveData'></SetReason>
  </div>
</template>

<script>
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import CheckAndEditModel from './CheckAndEditModel'
  import {butStatus} from '../butStatus'
  import columns from './indexColumns'
  import SelectApprove from '../../public/SelectApprover'
  import SetReason from "../../public/SetReason"
  import { postAction } from '@api/manage'

  export default {
    props: ['id', 'bsjdwName', 'bsjdw', 'protype', 'type', 'stage'],
    name: "sjwt",
    components: {
      CheckAndEditModel,
      SelectApprove,
      SetReason
    },
    mixins: [JeecgListMixin, butStatus],
    data() {
      return {
        genLoading:false,
        /* table选中keys*/
        selectedRowKeys: [],
        /* table选中records*/
        selectionRows: [],
        //表头
        queryParam: {
          proId: this.id,
          bsjdw: this.bsjdw
        },
        thisTypeId: '72',
        columns: columns(this),
        url: {
          list: '/sjxmzygl/sjWorkZtfaProblem/queryProblemSumList',
          delete: '/sjxmzygl/sjWorkZtfaEveYidian/remove',
          importExcelUrl: `${window._CONFIG['domianURL']}/sjxmzygl/sjWorkZtfaProblem/importExcel`,
          exportList: `${window._CONFIG['domianURL']}/sjxmzygl/sjWorkZtfaProblem/exportProblemInfo`,
          exportTemp: `${window._CONFIG['domianURL']}/sys/common/static/xls-template/sj_problem.xlsx`,
          submit: '/sjxmzygl/sjWorkZtfaEveDigao/approveDigao',
          approve: '/sjxmzygl/sjWorkZtfaEveDigao/approveDigao',
          generateReport: '/sjxmzygl/sjWorkBaogao/generateCg',
        }
      }
    },
    methods: {
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
      },
      handleGenerateReport() {
        this.genLoading = true
        postAction(this.url.generateReport, { proId: this.queryParam.proId, type: 'baogao_cg' }).then((res) => {
          if (res.success && res.result) {
            this.genLoading = false
            this.$message.success('正在下载，请稍等！')
            const url = `${window._CONFIG['domianURL']}/sys/common/static${res.result}`
            window.open(url, '_blank')
          } else {
            this.genLoading = false
            this.$message.error(res.message)
          }
        }).finally(() => {
          this.genLoading = false
        })
      }
    }
  }
</script>

<style scoped>

</style>